package top.yxqz.sprinmvc.ajax.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.yxqz.sprinmvc.ajax.pojo.Student;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: 余小小
 * @date: 2023/5/12
 * @description：
 */
@Controller
@RequestMapping("/axios")
public class AxiosController {
    /**
     * 跳转到axios页面—
     */
    @RequestMapping("/")
    public String axios() {
        return "axios_page";
    }

    /**
     * 返回一个数据---old
     * uri：/axios/old
     */
    @GetMapping("/old")
    public void dataByOld(HttpServletResponse response) throws IOException {
        response.getWriter().println("www.yxqz.top");
    }

    /**
     * 接收请求体的数据——————单个数据
     */
    @PostMapping("/req")
    public void getDataByRequestBody(@RequestBody String data, HttpServletResponse response) throws IOException {
        response.getWriter().println("你从请求体中获取的数据是：" + data);
    }

    /**
     * 接收请求体的数据——————多个数据(对象）
     */
    @PostMapping("/req2")
    public void getDataByRequestBody2(@RequestBody Student student, HttpServletResponse response) throws IOException {
        response.getWriter().println("你从请求体中获取的数据是：" + student);
    }

    /**
     * 响应体响应数据————单个数据
     */
    @PostMapping("/resp")
    @ResponseBody
    public String dataByResponse() {
        return "www.yxqz.top";
    }

    /**
     * 响应体响应数据————单个数据
     */
    @PostMapping("/resp2")
    @ResponseBody
    public Student dataByResponse2() {
        Student student = new Student("刘备", "111111", "24", "1234@qq.com");
        return student;
    }


}
